package edu.sctu.yueding.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import edu.sctu.yueding.R;
import edu.sctu.yueding.bean.NewsCommentsBean;

/**
 * Created by fll on 2016/8/22.
 */
public class NewsCommentAdapter extends BaseAdapter {

    private Activity activity;
    private List<NewsCommentsBean> list;
    private TextView commentText, commentName;

    public NewsCommentAdapter(Activity activity, List<NewsCommentsBean> list) {
        this.activity = activity;
        this.list = list;
    }

    public void onDateChange(List<NewsCommentsBean> data) {
        this.list = data;
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (list != null && list.size() > 0) {
            return list.size();
        } else {
            return 0;
        }
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {


//        System.out.println(commentNameText);

        if (convertView == null) {
            convertView = LayoutInflater.from(activity).inflate(R.layout.item_news_comment, null);
        }

        commentText = (TextView) convertView.findViewById(R.id.news_comment_content);
        commentName = (TextView) convertView.findViewById(R.id.news_user_name);
        commentText.setText(list.get(position).getContent());
        commentName.setText(list.get(position).getAuthorName() + " : ");
        return convertView;
    }
}
